package top.yazif.text;

import top.yazif.excel.ExcelImpl;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * Created by Yazif on 2017/3/18.
 */
public class ExcelImplTest {
    public static void main(String[] args) throws Exception {


        try (ExcelImpl excel1 = new ExcelImpl("./test/1.xlsx"); ExcelImpl excel2 = new ExcelImpl("./test/2.xlsx");) {
            Set<String> strings = new HashSet<String>();

            int rowCount = excel1.getNumberOfRows();
            for (int rowIndex = 1; rowIndex < rowCount; rowIndex++) {
                int colCount = excel1.getNumberOfCell(rowIndex);
                if (colCount != -1) {
                    for (int colIndex = 1; colIndex < colCount; colIndex++) {
                        String value = excel1.getValue(rowIndex, colIndex);
                        if (!"".equals(value)) {
                            strings.add(value);
                        }
                    }
                }
            }


            Iterator<String> it = strings.iterator();
            int colCount = (int) Math.sqrt(strings.size());
            int rowIndex = 1, colIndex = 1;
            while (it.hasNext()) {
                excel2.setCellValue(it.next(), rowIndex, colIndex++);
                if (colIndex > colCount) {
                    colIndex = 1;
                    rowIndex++;
                }
            }
        }
    }

}
